package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.Getter;

/**
 * 套餐校验错误类型
 * 创建时间 2019/6/26 2:31 PM
 * 修改时间 2019/6/26 2:31 PM
 * @author chy
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum PackageErrorEnum {
    /**
     * 套餐错误类型枚举
     */
    NORMAL(0, "enum.packageError.name.normal", 1),

    FREE_WILL_EXPIRE(3, "enum.packageError.name.free_will_expire", 1),

    FREE_EXPIRE(4, "enum.packageError.name.free_expire", 0),

    VIP_WILL_EXPIRE(7, "enum.packageError.name.vip_will_expire", 1),

    VIP_EXPIRE(8, "enum.packageError.name.vip_expire", 0),

    USER_COUNT_OVER(9, "enum.packageError.name.user_count_over", 0),

    NOT_STARTED(11, "enum.packageError.name.not_started", 0),

    UNKNOWN(404, "enum.packageError.name.unknown", 0);
    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;

    /**
     * 枚举信息--是否可用
     */
    private final int isActive;

    /**
     * 构造一个<code>AppStoreTypeEnum</code>枚举对象
     *
     * @param code  枚举Code
     * @param name  枚举名称
     */
    PackageErrorEnum(int code, String name, int isActive) {
        this.code = code;
        this.name = name;
        this.isActive = isActive;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     * @return AppStoreTypeEnum
     */
    public static PackageErrorEnum getByCode(Integer code) {
        for (PackageErrorEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getCode(), code)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<PackageErrorEnum>
     */
    public List<PackageErrorEnum> getAllEnum() {
        List<PackageErrorEnum> list = new ArrayList<>();
        for (PackageErrorEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
